﻿using MediatR;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure;

namespace Traceability.App.Applications.Traceability
{
    public class GoodsQueryCommandHandler : IRequestHandler<GoodsQueryCommand, APIResult<List<T_Goods>>>
    {
        private readonly IBaseRepository<T_Goods> goodsRepository;

        public GoodsQueryCommandHandler(IBaseRepository<T_Goods> goodsRepository)
        {
            this.goodsRepository = goodsRepository;
        }

        public Task<APIResult<List<T_Goods>>> Handle(GoodsQueryCommand request, CancellationToken cancellationToken)
        {

            APIResult<List<T_Goods>> result = new APIResult<List<T_Goods>>();
            result.Code = APIEnum.ok;
            result.Message = "获取成功";
            var list = goodsRepository.GetAll().ToList();
            result.Data = list;
            return Task.FromResult(result);
        }
    }
}
